package com.jd.service.impl;

import com.jd.domain.User;
import com.jd.mapper.UserMapper;
import com.jd.service.IUserService;
import com.jd.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class UserServiceImpl implements IUserService {

    @Override
    public List<User> findAll() {
        SqlSession sqlSession = MybatisUtils.openSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> userList = mapper.findAll();
        return userList;
    }

    @Override
    public void batchAddUser(List<User> users) {
        SqlSession sqlSession = MybatisUtils.openSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        mapper.batchAddUser(users);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void batchDelUser(Long[] ids) {
        SqlSession sqlSession = MybatisUtils.openSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        mapper.batchDelUser(ids);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public List<User> findAllUserAndOrder() {
        SqlSession sqlSession = MybatisUtils.openSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        List<User> allUserAndOrder = mapper.findAllUserAndOrder();
        return allUserAndOrder;
    }
}
